import {Component, Injector, OnInit} from '@angular/core';
import {Product, ProductService} from '../product.service';

@Component({
  selector: 'app-product1',
  templateUrl: './product1.component.html',
  styleUrls: ['./product1.component.css']
})
export class Product1Component implements OnInit {

  private product: Product;
  private productService: ProductService;

  constructor(injector: Injector) {
    // 应避免这样做，只有开发框架，通用或动态注入依赖才考虑
    this.productService = injector.get(ProductService);
  }

  ngOnInit() {
    this.product = this.productService.getProduct();
  }

}
